package com.agile.leetcode.jdk8.localdatetime;

import java.time.LocalDateTime;

/**
 * jdk1.8新特性新加的类
 *
 * @Author:ChenZhangKun
 * @Date: 2020/12/29 22:26
 */
public class LocalDateTimeDemo {
    public static void main(String[] args) {
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
        // 获取分别时间
        // 年
        System.out.println(now.getYear());
        // 月
        System.out.println(now.getMonth());
        // 日
        System.out.println(now.getDayOfYear());
        // 时
        System.out.println(now.getHour());
        // 分
        System.out.println(now.getMinute());
        // 秒
        System.out.println(now.getSecond());
        // 手动创建时间
        LocalDateTime dateTime = LocalDateTime.of(2020, 12, 12, 12, 20, 59);
        System.out.println(dateTime);
        // 日期加一天
        LocalDateTime localDateTime = dateTime.plusDays(11L);
        System.out.println(localDateTime);
        // 日期减十天
        LocalDateTime localDateTime1 = dateTime.minusDays(10L);
        System.out.println(localDateTime1);
    }
}
